/*++ Module: Generate Programming Assignment #3 CSE 373 2000 Winter Quarter University of Washington Description: This module generates the test data for the 3rd programming assignment Author: Gary Kimura [GaryKi@cs.washington.edu] 20-Feb-2000 Revision History: --*/ #include #include void main( int argc, char *argv[] ) /*++ Routine Description: This routine generate the lotto test data The optional arguments to the program are generate where is the number of entries to output (default is 1,000,000) is the maximum value each entry can choose from (default is 55) Arguments: argc - The number of command line arguments argv - The actual command line arguments Return Value: None. --*/ { clock_t Start, Finish; unsigned int i; unsigned int Lotto[6]; unsigned int WinningId; unsigned int WinningNumbers[6]; unsigned int Size; unsigned int Range; // // Start the time // Start = clock(); // // Seed the random number generator // srand(373); // // Read in the size and range if supplied by the user // if (argc > 1) { sscanf( argv[1], "%d", &Size ); } else { Size = 1000000; } if (argc > 2) { sscanf( argv[2], "%d", &Range ); } else { Range = 55; } // // Compute the one winning ID // WinningId = (rand() << 16 | rand()) % Size; // // Now loop through generating entries // for (i = 0; i < Size; i += 1) { Lotto[0] = (rand() % Range) + 1; for (Lotto[1] = (rand() % Range) + 1; Lotto[1] == Lotto[0]; Lotto[1] = (rand() % Range) + 1); for (Lotto[2] = (rand() % Range) + 1; Lotto[2] == Lotto[1] || Lotto[2] == Lotto[0]; Lotto[2] = (rand() % Range) + 1); for (Lotto[3] = (rand() % Range) + 1; Lotto[3] == Lotto[2] || Lotto[3] == Lotto[1] || Lotto[3] == Lotto[0]; Lotto[3] = (rand() % Range) + 1); for (Lotto[4] = (rand() % Range) + 1; Lotto[4] == Lotto[3] || Lotto[4] == Lotto[2] || Lotto[4] == Lotto[1] || Lotto[4] == Lotto[0]; Lotto[4] = (rand() % Range) + 1); for (Lotto[5] = (rand() % Range) + 1; Lotto[5] == Lotto[4] || Lotto[5] == Lotto[3] || Lotto[5] == Lotto[2] || Lotto[5] == Lotto[1] || Lotto[5] == Lotto[0]; Lotto[5] = (rand() % Range) + 1); printf("%d %d %d %d %d %d %d \n", i+10000, Lotto[0], Lotto[1], Lotto[2], Lotto[3], Lotto[4], Lotto[5]); // // Check if this should be the winning entry // if (WinningId == i) { WinningNumbers[0] = Lotto[1]; WinningNumbers[1] = Lotto[4]; WinningNumbers[2] = Lotto[2]; WinningNumbers[3] = Lotto[5]; WinningNumbers[4] = Lotto[3]; WinningNumbers[5] = Lotto[0]; } } // // Print out the winning combination // printf("%d %d %d %d %d %d %d \n", 0, WinningNumbers[0], WinningNumbers[1], WinningNumbers[2], WinningNumbers[3], WinningNumbers[4], WinningNumbers[5]); // // Calculate how long this took us do // Finish = clock(); fprintf(stderr, "Start = %d\n", Start); fprintf(stderr, "Finish = %d\n", Finish); fprintf(stderr, "generate took %f seconds to execute\n", ((double)(Finish-Start))/CLK_TCK); return; }